﻿namespace Harness.Commands
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    internal class AssertCommand : ICommand
    {
        #region Constants

        private const int AssertTypeArgIndex = 0;
        private const int ExpectedArgIndex = 1;

        #endregion

        #region Public Methods

        public void SyntaxCheck(IHarness harness, IEnumerable<object> args)
        {
            Verification.SyntaxCheck(harness, args);
        }

        public dynamic Execute(IHarness harness, IEnumerable<object> args)
        {
            if (Verification.IsFalse(harness, args))
            {
                string msg = string.Format(
                    Properties.Resources.Exception_AssertFailed,
                    args.ElementAtOrDefault(AssertTypeArgIndex) ?? string.Empty,
                    args.ElementAtOrDefault(ExpectedArgIndex) ?? string.Empty);

                throw new InvalidOperationException(msg);
            }

            return null;
        }

        #endregion
    }
}
